﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using DataAccess;

namespace BusinessLayer2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ProductServices" in code, svc and config file together.
    public class ProductServices : IProductServices
    {
        /// <summary>
        /// Getting all products that are stored in the databse
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.Product> GetAllProducts()
        {
            return new ProductRepository().GetAllProducts();
        }

        /// <summary>
        /// Searching a product with the parameters specifed
        /// </summary>
        /// <param name="category"></param>
        /// <param name="name"></param>
        /// <param name="LeastPrice"></param>
        /// <param name="MaxPrice"></param>
        /// <returns></returns>
        public IEnumerable<Common.Product> Search(int category, string name, int LeastPrice, int MaxPrice)
        {
            return new ProductRepository().SearhProduct(category, name, LeastPrice, MaxPrice);
        }

        /// <summary>
        /// Updating the selected product details
        /// </summary>
        /// <param name="p"></param>
        public void UpdateProduct(Common.Product p)
        {
            new ProductRepository().UpdateProduct(p);
        }

        /// <summary>
        /// Getting the product details of the product that has the same selected ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Common.Product GetProductByID(int id)
        {
            return new ProductRepository().GetProductByID(id);
        }

        /// <summary>
        /// Adding the rating of a product according to a user
        /// </summary>
        /// <param name="UPS"></param>
        public void AddRating(Common.UserProductRating u)
        {
            new ProductRepository().AddRating(u);
        }

        /// <summary>
        /// Adding the Products to a shopping cart
        /// </summary>
        /// <param name="t"></param>
        public void AddToCart(string username,int productID, int quantity)
        {
            new CartRepository().AddtoCart(username,productID,quantity);
        }

        /// <summary>
        /// Getting all catgeories from the database
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.Category> GetAllCategories()
        {
            return new ProductRepository().GetAllCategories();
        }

        /// <summary>
        /// Getting all item of the user shopping cart
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public List<Common.Cart> GetItemsInShoppingCart(string username)
        {
            return new CartRepository().GetUserNameCart(username).ToList();
        }

        /// <summary>
        /// Adding the product detail of the product bought
        /// </summary>
        /// <param name="od"></param>
        public void AddOrderDetails(Common.OrderDetail od)
        {
            new OrderReposity().AddOrderDetail(od);
        }

        /// <summary>
        /// Removing a product from the user shopping cart
        /// </summary>
        /// <param name="Id"></param>
        public void RemoveProductFromCart(int Id)
        {
            new CartRepository().RemoveProductFromCart(Id);
        }

        /// <summary>
        /// Gtting all comments on a particular product
        /// </summary>
        /// <param name="ProductID"></param>
        /// <returns></returns>
        public List<Common.Comment> getComments(int ProductID)
        {
            return new ProductRepository().getComments(ProductID);
        }
        /// <summary>
        /// Add a new comment to a product
        /// </summary>
        /// <param name="c"></param>
        public void addComment(Common.Comment c)
        {
            new ProductRepository().addComment(c);
        }

        /// <summary>
        /// Getting the number of item there is in a username Cart
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public int GetNoOfItemsInShoppingCart(string username)
        {
            return new CartRepository().GetNoOfItemsInShoppingCart(username);
        }

        /// <summary>
        /// Getting 
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public Common.VIews.UserItem GetUserProductsDetails(string username,int id)
        {
            return new ProductRepository().GetUserProductsDetails(username, id);
        }

        /// <summary>
        /// Getting all Items that the user have purchased
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public IEnumerable<Common.VIews.UserItem> GetUserProducts(string username)
        {
            return new ProductRepository().GetUserProducts(username);
        }

        public void AddOrder(Common.Order O)
        {
            new OrderReposity().AddOrder(O);
        }

        public void DeleteCart(int id)
        {
            new CartRepository().DeleteCart(id);
        }

        public IEnumerable<Common.VIews.UserItem> GetUserProductsForFaults(string username)
        {
            return new ProductRepository().GetUserProductsForFaults(username);
        }

        public IEnumerable<Common.Product> GetAllUserProducts(string username)
        {
            return new ProductRepository().GetAllUserProducts(username);
        }

        public Common.Views.ProductDetails GetProductDetailsByID(int id, string username)
        {
            return new ProductRepository().GetProductDetailsByID(id, username);
        }


        public IEnumerable<Common.OrderDetail> GettAllOrdersDetails()
        {
            return new OrderReposity().GettAllOrdersDetails();
        }

        public IEnumerable<Common.UserProductRating> getAllRatings()
        {
            return new ProductRepository().getAllRatings();
        }

        public string PDFOrder(Guid orderId)
        {
            return new ProductRepository().PDFOrder(orderId);
        }

        public Common.Order GetOrderByID(Guid ID)
        {
            return new OrderReposity().GetOrderByID(ID);
        }

        public Common.OrderDetail GetOrderDetailByID(int id)
        {
            return new OrderReposity().GetOrderDetailByID(id);
        }

        public IEnumerable<Common.OrderDetail> GetOrderDetailByOrderID(Guid id)
        {
            return new OrderReposity().GetOrderDetailByOrderID(id);
        }

        public void UpdateOrderDetail(Common.OrderDetail od)
        {
            new OrderReposity().UpdateOrderDetail(od);
        }


        public IEnumerable<Common.Order> GetAllOrderByUserName(string username)
        {
            return new OrderReposity().GetAllOrderByUserName(username);
        }


        public void ProduceReport(List<Common.Views.ProductReport> list, string opt)
        {
            new ProductRepository().ProduceReport(list, opt);
        }
    }
}
